#pragma once
#include "Manager.h"
#include <iostream>
#include "msclr\marshal_cppstd.h"

namespace CS2103v01 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for DeleteCategory
	/// </summary>
	public ref class DeleteCategory : public System::Windows::Forms::Form
	{
	public:
		DeleteCategory(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			TM = Manager::get();
			setUpComboBox("cat",comboBox1);
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~DeleteCategory()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::ComboBox^  comboBox1;

	private:
		/// <summary>
		/// Required designer variable.
		Manager* TM;
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft YaHei", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->button1->Location = System::Drawing::Point(265, 176);
			this->button1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(87, 33);
			this->button1->TabIndex = 0;
			this->button1->Text = L"OK";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &DeleteCategory::button1_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft YaHei", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->label1->Location = System::Drawing::Point(73, 91);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(61, 17);
			this->label1->TabIndex = 1;
			this->label1->Text = L"Category";
			// 
			// comboBox1
			// 
			this->comboBox1->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->comboBox1->Font = (gcnew System::Drawing::Font(L"Microsoft YaHei", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->comboBox1->FormattingEnabled = true;
			this->comboBox1->Location = System::Drawing::Point(181, 85);
			this->comboBox1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4);
			this->comboBox1->Name = L"comboBox1";
			this->comboBox1->Size = System::Drawing::Size(140, 25);
			this->comboBox1->TabIndex = 2;
			// 
			// DeleteCategory
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(7, 17);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(394, 249);
			this->Controls->Add(this->comboBox1);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->button1);
			this->Font = (gcnew System::Drawing::Font(L"Microsoft YaHei", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->Margin = System::Windows::Forms::Padding(3, 4, 3, 4);
			this->Name = L"DeleteCategory";
			this->Text = L"Delete Category";
			this->Load += gcnew System::EventHandler(this, &DeleteCategory::DeleteCategory_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void DeleteCategory_Load(System::Object^  sender, System::EventArgs^  e) {
				 setUpComboBox("cat",comboBox1);
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 string OLD="";
				 OLD = msclr::interop::marshal_as<std::string>(comboBox1->Text);

				 if(TM->delCategory(OLD))
					 {
						 MessageBox::Show("Successful!");
						 this->Close();
					 }
					 else
						 MessageBox::Show("The category you wanted to delete does not exist!");
			 }
	private: void setUpComboBox(string type, ComboBox^CB)
			 {
				 if(type=="acc")
				 {
					 CB->Items->Clear();
					 if(!((TM->getAccAddr())->empty()))
					 {
						 list<string>::iterator iterA;
						 String ^ tempAcc;
						 for(iterA = (TM->getAccAddr())->begin(); iterA != (TM->getAccAddr())->end(); iterA++)
						 {
							 if(*iterA!="delete" && *iterA!="Cash")
							 {
								 tempAcc =  msclr::interop::marshal_as<System::String^>(*iterA);
								 CB->Items->Add(tempAcc);
							 }
						 }
						 CB->SelectedIndex = 0;
					 }
				 }
				 else if(type=="cat")
				 {
					 CB->Items->Clear();

					 if(!((TM->getCatAddr())->empty()))
					 {
						 list<string>::iterator iterC = TM->getCatAddr()->begin();
						 String ^ tempCat;
						 for(; iterC != (TM->getCatAddr())->end(); iterC++)
						 {
							 if(*iterC!="Income" && *iterC!="Transfer" && *iterC!="Others")
							 {
								 tempCat =  msclr::interop::marshal_as<System::String^>(*iterC);
								 CB->Items->Add(tempCat);
							 }
						 }
						 CB->SelectedIndex = 0;
					 }
				 }
				 else if(type=="hour")
				 {
					 struct tm *sysTime;
					 time_t *rawSysTime;
					 rawSysTime = new time_t;
					 time(rawSysTime);
					 sysTime = localtime(rawSysTime);
					 CB->SelectedIndex = sysTime->tm_hour;
					 delete rawSysTime;
				 }
				 else if(type=="min")
				 {
					 struct tm *sysTime;
					 time_t *rawSysTime;
	 				 rawSysTime = new time_t;
					 time(rawSysTime);
					 sysTime = localtime(rawSysTime);
					 CB->SelectedIndex = sysTime->tm_min;
					 delete rawSysTime;
				 }

				 else
					 return;
			 }
	};
}
